package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.service.FoodMealsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.FoodMeals;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜品Controller
 *
 * @author xianpei
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/meals/meals")
public class FoodMealsController extends BaseController
{
    @Autowired
    private FoodMealsService foodMealsService;

    /**
     * 查询菜品列表
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:list')")
    @GetMapping("/list")
    public TableDataInfo list(FoodMeals foodMeals)
    {
        startPage();
        List<FoodMeals> list = foodMealsService.selectFoodMealsList(foodMeals);
        return getDataTable(list);
    }

    /**
     * 导出菜品列表
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:export')")
    @Log(title = "菜品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodMeals foodMeals)
    {
        List<FoodMeals> list = foodMealsService.selectFoodMealsList(foodMeals);
        ExcelUtil<FoodMeals> util = new ExcelUtil<FoodMeals>(FoodMeals.class);
        util.exportExcel(response, list, "菜品数据");
    }

    /**
     * 获取菜品详细信息
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:query')")
    @GetMapping(value = "/{mealsId}")
    public AjaxResult getInfo(@PathVariable("mealsId") Long mealsId)
    {
        return success(foodMealsService.selectFoodMealsByMealsId(mealsId));
    }

    /**
     * 新增菜品
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:add')")
    @Log(title = "菜品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FoodMeals foodMeals)
    {
        return toAjax(foodMealsService.insertFoodMeals(foodMeals));
    }

    /**
     * 修改菜品
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:edit')")
    @Log(title = "菜品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FoodMeals foodMeals)
    {
        return toAjax(foodMealsService.updateFoodMeals(foodMeals));
    }

    /**
     * 删除菜品
     */
    @PreAuthorize("@ss.hasPermi('meals:meals:remove')")
    @Log(title = "菜品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mealsIds}")
    public AjaxResult remove(@PathVariable Long[] mealsIds)
    {
        return toAjax(foodMealsService.deleteFoodMealsByMealsIds(mealsIds));
    }
}
